package com.tbit.uqbike.webmanager.business.maintain_performance.object.dto.stat;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tbit.uqbike.annos.Excel;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 维修绩效详情
 *
 * @author <a href="mailto:zheng.zebiao@tbit.com.cn">zb</a>
 * @since 2025/3/3
 */
@Data
public class RepairPerformanceDetail {
    /**
     * 主键
     */
    private Long performanceId;

    /**
     * 维修记录id
     */
    private Integer repairLogId;

    /**
     * 绩效系数
     */
    @Excel(name = "绩效系数", sort = 8)
    private BigDecimal performance;

    /**
     * 绩效详情
     */
    @Excel(name = "绩效详情", sort = 9)
    private String performanceDetail;

    /**
     * 备注
     */
    @Excel(name = "备注", sort = 10)
    private String remark;

    /**
     * 维修时间
     */
    @Excel(name = "日期", sort = 1, dateFormat = "yyyy-MM-dd")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime repairTime;

    /**
     * 车辆编号
     */
    @Excel(name = "车辆编码", sort = 2)
    private String userCode;

    /**
     * 区域id
     */
    private Integer accountId;

    /**
     * 运维人员id
     */
    private Integer accountUserId;
    /**
     * 运维人员姓名
     */
    @Excel(name = "运维人姓名", sort = 3)
    private String accountUserName;
    /**
     * 运维人员手机
     */
    @Excel(name = "运维人手机号", sort = 4)
    private String accountUserPhone;
    /**
     * 维修类型
     */
    private String repairTypes;

    /**
     * 维修类型(excel导出用)
     */
    @JsonIgnore
    @JSONField(serialize = false)
    @Excel(name = "维修类型", sort = 5)
    private String repairTypesRemark;

    /**
     * 维修图片链接，多个图片用逗号分隔
     */
    @Excel(name = "维修图片", sort = 6)
    private String repairImages;

    /**
     * 维修状态
     */
    @Excel(name = "维修状态", sort = 7, readConverterExp = "0=未维修,1=维修完成")
    private Integer repairState;


    /**
     * 解析维修类型
     */
    public void parseRepairTypes(){
        if (StrUtil.isEmpty(repairTypes)){
            return;
        }

        StringBuilder type = new StringBuilder();
        String[] list = this.repairTypes.split(",");
        for (String s : list) {
            switch (s) {
                case "0":
                    type.append("转把手").append(",");
                    break;
                case "1":
                    type.append("车灯").append(",");
                    break;
                case "2":
                    type.append("线路").append(",");
                    break;
                case "3":
                    type.append("车篮").append(",");
                    break;
                case "4":
                    type.append("车轮").append(",");
                    break;
                case "5":
                    type.append("车撑").append(",");
                    break;
                case "6":
                    type.append("刹车").append(",");
                    break;
                case "7":
                    type.append("车座").append(",");
                    break;
                case "8":
                    type.append("二维码").append(",");
                    break;
                case "9":
                    type.append("电池").append(",");
                    break;
                case "10":
                    type.append("脚蹬").append(",");
                    break;
                case "11":
                    type.append("前叉").append(",");
                    break;
                case "12":
                    type.append("挡泥板").append(",");
                    break;
                case "13":
                    type.append("控制器").append(",");
                    break;
                case "14":
                    type.append("中控").append(",");
                    break;
                case "15":
                    type.append("响铃铛").append(",");
                    break;
                case "16":
                    type.append("电池锁").append(",");
                    break;
                //兼容ios和安卓
                case "17":
                case "50":
                    type.append("其他").append(",");
                    break;
                default:
                    break;
            }
        }
        String s = type.toString();
        if (StringUtils.isNotBlank(s) && s.endsWith(",")) {
            s = s.substring(0, s.length() - 1);
        }
        this.repairTypesRemark = s;
    }
}
